import { createRouter, RoutePathLocation } from '@gowiny/uni-router'
import PAGE_DATA from '@/pages.json'
import store from "../store/index.js"
const router = createRouter({
	pageData: PAGE_DATA
})

router.beforeEach((to, from) => {
	/* 挂载每个页面 */
	store.commit("SET_PATH_PAGR",to.fullPath);

	if (to.path != '/pages/login/login') {
		const isLog = store.state.isLoginOut
		if (isLog) {
			return
		}
		try {
			const loginInfo = uni.getStorageSync('uni-id-pages-userInfo');
			if (loginInfo ) {
				// 缓存信息未过期
				store.commit("SET_USER_INFO", {user: loginInfo})
			} else {
				setTimeout(() => { uni.reLaunch({ url: '/pages/login/login' }) },10)
			}
		} catch (e) {
			setTimeout(() => { uni.reLaunch({ url: '/pages/login/login' }) },10)
		}
	}
	
})

export default router